<?php
/**
 * Created by PhpStorm.
 * User: zcq
 * Date: 2018/10/22
 * Time: 10:50
 */

namespace app\index\model;



use app\common\RedisCache;

class VoteType extends BaseModel
{
    const TABLE = 'vote_type';

    const ENABLE_YES = 1;
    const ENABLE_NO =2;

    public static function getList($voteId)
    {
        //活动暂时缓存一个月
        $key = 'vote_type_'.$voteId;
        $expireTime = 30*24*3600;
        $type = RedisCache::getInstance()->cache($key);
        if($type)
            return json_decode($type,1);

        $type = self::where('vote_id',$voteId)->where('enable',self::ENABLE_YES)->order('sort desc,id desc')->select();
        if($type){
            RedisCache::getInstance()->cache($key,json_encode($type,JSON_UNESCAPED_UNICODE),$expireTime);
        }

        return $type;
    }
}